import java.util.Arrays;
import java.util.LinkedList;

/**
 * @author malguy-wang sir
 * @create ---
 */
public class myLinkListHashMap<K, V> implements myMap<K, V> {
    private LinkedList<Node>[] objects = new LinkedList[100];
    @Override
    public int size() {
        return 0;
    }
    public void show() {
        for (Object node : objects) {
            if (node != null) System.out.println(node);
        }
    }
    @Override
    public V get(K key) {
        int index = key.hashCode() % objects.length;
        LinkedList<Node> nodes = objects[index];//获取哈希值对应的链表
        for (Node node : nodes) {
            if(node.getKey().equals(key)){
                return node.getValue();
            }
        }
        return null;
    }
    @Override
    public V put(K key, V value) {
        int index = (key.hashCode()) % objects.length;
        LinkedList nodes = objects[index];
        //如果不存在hash冲突(hash值相等,对象值不等)
        if(nodes==null){
            nodes = new LinkedList<Node>();//现在存值的已经改为linkedlist,这里把
        }
        nodes.add(new Node(key,value));
        objects[index]=nodes;
        return value;
    }
    private class Node implements entry<K, V> {
        private K key;
        private V value;
        public Node(K key, V value) {
            this.key = key;
            this.value = value;
        }
        @Override
        public K getKey() { return key; }
        @Override
        public V getValue() { return value; }
        @Override
        public String toString() {
            return "Node{" +
                    "key=" + key +
                    ", value=" + value +
                    '}';
        }
    }
}
